import { d as defineComponent, s as storeToRefs, r as ref, k as onMounted, o as openBlock, c as createElementBlock, b as createVNode, w as withCtx, f as createBaseVNode, m as withKeys, g as createBlock, x as createCommentVNode, a as resolveComponent, h as unref, n as search_default } from "./index-NZguwuNX.js";
import { u as useCounterStore, h as http } from "./index-F6B3vg3q.js";
import { _ as _sfc_main$1 } from "./Pagination.vue_vue_type_script_setup_true_lang-x-Hoizt3.js";
const _hoisted_1 = { class: "df jc-sb title-btn" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "log",
  setup(__props) {
    const store = useCounterStore();
    const { userInfo } = storeToRefs(store);
    const tableData = ref([]);
    const activeName = ref("agentuserlog");
    const time_prefix = ref([]);
    onMounted(async () => {
      time_prefix.value = time((/* @__PURE__ */ new Date()).getTime());
      console.log(time_prefix.value);
      tableData.value = await operat_sql(
        `SELECT * FROM ${time_prefix.value[0].t}${time_prefix.value[0].name} ORDER BY  ${time_prefix.value[0].t}${time_prefix.value[0].name}.ID LIMIT 15 OFFSET 0`,
        "usergloballog"
      );
      console.log(tableData.value);
      let total_arr = await operat_sql(`SELECT COUNT(*) FROM ${time_prefix.value[0].t}${time_prefix.value[0].name}`, "usergloballog");
      total.value = Number(total_arr[0]["COUNT(*)"]);
      console.log(total_arr);
    });
    const operat_sql = async (sql, dbName) => {
      const res = await http.corsApi("/", "post", {
        packID: "123456",
        packageType: "adminSql",
        packageContent: {
          AgentUserName: userInfo.value.username,
          AgentUserPassword: userInfo.value.password,
          sql,
          dbName
        }
      });
      let data = [];
      if (res.packageContent.packageMsg == "成功") {
        data = [];
      } else {
        data = JSON.parse(res.packageContent.packageMsg);
      }
      console.log(res);
      return data;
    };
    const tab_index = ref(0);
    const tab_Click = async (tab, event) => {
      console.log(tab, event);
      tab_index.value = tab.index;
      page.value = 1;
      pageSize.value = 15;
      tableData.value = await operat_sql(
        `SELECT * FROM ${time_prefix.value[tab.index].t}${time_prefix.value[tab.index].name} ORDER BY ${time_prefix.value[tab.index].t}${time_prefix.value[tab.index].name}.ID LIMIT 15 OFFSET 0`,
        "usergloballog"
      );
      let total_arr = await operat_sql(`SELECT COUNT(*) FROM ${time_prefix.value[tab.index].t}${time_prefix.value[tab.index].name}`, "usergloballog");
      total.value = Number(total_arr[0]["COUNT(*)"]);
      console.log(total_arr);
    };
    const page = ref(1);
    const pageSize = ref(15);
    const total = ref(10);
    const handleSizeChange = async (val) => {
      console.log(`${val} items per page`);
      pageSize.value = val;
      if ((page.value - 1) * pageSize.value - 1 <= 0) {
        tableData.value = await operat_sql(
          `SELECT * FROM ${time_prefix.value[tab_index.value].t}${time_prefix.value[tab_index.value].name} ORDER BY ${time_prefix.value[tab_index.value].t}${time_prefix.value[tab_index.value].name}.ID LIMIT ${pageSize.value}  OFFSET 0`,
          "usergloballog"
        );
      } else {
        tableData.value = await operat_sql(
          `SELECT * FROM ${time_prefix.value[tab_index.value].t}${time_prefix.value[tab_index.value].name} ORDER BY ${time_prefix.value[tab_index.value].t}${time_prefix.value[tab_index.value].name}.ID LIMIT ${pageSize.value} OFFSET ${(page.value - 1) * pageSize.value}`,
          "usergloballog"
        );
      }
    };
    const handleCurrentChange = async (val) => {
      console.log(`current page: ${val}`);
      page.value = val;
      if ((page.value - 1) * pageSize.value - 1 <= 0) {
        tableData.value = await operat_sql(
          `SELECT * FROM ${time_prefix.value[tab_index.value].t}${time_prefix.value[tab_index.value].name} ORDER BY ${time_prefix.value[tab_index.value].t}${time_prefix.value[tab_index.value].name}.ID LIMIT ${pageSize.value}  OFFSET 0`,
          "usergloballog"
        );
      } else {
        tableData.value = await operat_sql(
          `SELECT * FROM ${time_prefix.value[tab_index.value].t}${time_prefix.value[tab_index.value].name} ORDER BY ${time_prefix.value[tab_index.value].t}${time_prefix.value[tab_index.value].name}.ID LIMIT ${pageSize.value} OFFSET ${(page.value - 1) * pageSize.value}`,
          "usergloballog"
        );
      }
    };
    const is_search = ref(true);
    const search_inp = ref("");
    const search_click = async () => {
      if (search_inp.value == "") {
        is_search.value = true;
        tableData.value = await operat_sql(
          `SELECT * FROM ${time_prefix.value[tab_index.value].t}${time_prefix.value[tab_index.value].name} ORDER BY ${time_prefix.value[tab_index.value].t}${time_prefix.value[tab_index.value].name}.ID LIMIT 15 OFFSET 0`,
          "usergloballog"
        );
      } else {
        is_search.value = false;
        tableData.value = await operat_sql(
          `SELECT * FROM ${time_prefix.value[tab_index.value].t}${time_prefix.value[tab_index.value].name} WHERE  ID LIKE '%${search_inp.value}%' OR Op_User LIKE '%${search_inp.value}%'OR OpType LIKE '%${search_inp.value}%'OR OpContent LIKE '%${search_inp.value}%'`,
          "usergloballog"
        );
      }
      let total_arr = await operat_sql(`SELECT COUNT(*) FROM ${time_prefix.value[tab_index.value].t}${time_prefix.value[tab_index.value].name}`, "usergloballog");
      total.value = Number(total_arr[0]["COUNT(*)"]);
    };
    const day_model = ref((/* @__PURE__ */ new Date()).getTime());
    const disabledDate = (time2) => {
      return time2.getTime() > Date.now();
    };
    const data_change = async (val) => {
      console.log(val);
      console.log(time(val));
      time_prefix.value = time(val);
      tableData.value = await operat_sql(
        `SELECT * FROM ${time_prefix.value[0].t}${time_prefix.value[0].name} ORDER BY  ${time_prefix.value[0].t}${time_prefix.value[0].name}.ID LIMIT 15 OFFSET 0`,
        "usergloballog"
      );
    };
    function time(t) {
      var dt = new Date(t);
      var y = dt.getFullYear();
      var m = dt.getMonth() + 1;
      var d = dt.getDate();
      m = m < 10 ? "0" + m : m;
      d = d < 10 ? "0" + d : d;
      return [
        { name: "agentuserlog", t: `${y}${m}${d}` },
        { name: "owneruserlog", t: `${y}${m}${d}` },
        { name: "webuserlog", t: `${y}${m}${d}` }
      ];
    }
    return (_ctx, _cache) => {
      const _component_el_tab_pane = resolveComponent("el-tab-pane");
      const _component_el_tabs = resolveComponent("el-tabs");
      const _component_el_button = resolveComponent("el-button");
      const _component_el_input = resolveComponent("el-input");
      const _component_el_date_picker = resolveComponent("el-date-picker");
      const _component_el_table_column = resolveComponent("el-table-column");
      const _component_el_table = resolveComponent("el-table");
      return openBlock(), createElementBlock("div", null, [
        createVNode(_component_el_tabs, {
          modelValue: activeName.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => activeName.value = $event),
          class: "demo-tabs",
          onTabClick: tab_Click
        }, {
          default: withCtx(() => [
            createVNode(_component_el_tab_pane, {
              label: "代理日志",
              name: "agentuserlog"
            }),
            createVNode(_component_el_tab_pane, {
              label: "网吧日志",
              name: "owneruserlog"
            }),
            createVNode(_component_el_tab_pane, {
              label: "用户日志",
              name: "webuserlog"
            })
          ]),
          _: 1
        }, 8, ["modelValue"]),
        createBaseVNode("div", _hoisted_1, [
          createBaseVNode("div", null, [
            createVNode(_component_el_input, {
              size: "small",
              modelValue: search_inp.value,
              "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => search_inp.value = $event),
              onKeydown: withKeys(search_click, ["enter"]),
              placeholder: "输入任意字段进行模糊查询",
              class: "input-with-select"
            }, {
              append: withCtx(() => [
                createVNode(_component_el_button, {
                  size: "small",
                  onClick: search_click,
                  icon: unref(search_default)
                }, null, 8, ["icon"])
              ]),
              _: 1
            }, 8, ["modelValue"])
          ]),
          createBaseVNode("div", null, [
            createVNode(_component_el_date_picker, {
              modelValue: day_model.value,
              "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => day_model.value = $event),
              type: "date",
              placeholder: "请选择日期",
              "disabled-date": disabledDate,
              size: "small",
              "value-format": "x",
              onChange: data_change
            }, null, 8, ["modelValue"])
          ])
        ]),
        createVNode(_component_el_table, {
          data: tableData.value,
          style: { "width": "100%", "margin-top": "15px", "height": "640px" },
          border: ""
        }, {
          default: withCtx(() => [
            createVNode(_component_el_table_column, {
              prop: "ID",
              label: "",
              width: "80"
            }),
            createVNode(_component_el_table_column, {
              prop: "OpTime",
              label: "操作时间",
              width: "180"
            }),
            createVNode(_component_el_table_column, {
              prop: "Op_User",
              label: "操作账号",
              width: "200"
            }),
            createVNode(_component_el_table_column, {
              prop: "OpType",
              label: "操作类型",
              width: "200"
            }),
            createVNode(_component_el_table_column, {
              prop: "OpContent",
              label: "操作内容"
            })
          ]),
          _: 1
        }, 8, ["data"]),
        is_search.value ? (openBlock(), createBlock(_sfc_main$1, {
          key: 0,
          style: { "margin-top": "10px" },
          total: total.value,
          onHandleSizeChange: handleSizeChange,
          onHandleCurrentChange: handleCurrentChange
        }, null, 8, ["total"])) : createCommentVNode("", true)
      ]);
    };
  }
});
export {
  _sfc_main as default
};
